package id.agung.wonogirimaps.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TwoListItemAdapter extends BaseAdapter
{
	static class ViewHolder
	{
		ImageView	ImgThumb;
		TextView	TxtTitle;
	}

	private String[]		title;
	private int[]			img;
	private LayoutInflater	inflater;
	private int				idLayout;
	private int				idThumbImg;
	private int				idTitleTxt;

	public TwoListItemAdapter(Context context, String[] title, int[] img,
			int idLayout, int idThumbImg, int idTitleTxt)
	{
		inflater = LayoutInflater.from(context);
		this.title = title;
		this.img = img;
		this.idLayout = idLayout;
		this.idThumbImg = idThumbImg;
		this.idTitleTxt = idTitleTxt;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return title.length;
	}

	@Override
	public Object getItem(int arg0)
	{
		// TODO Auto-generated method stub
		return title[arg0];
	}

	@Override
	public long getItemId(int arg0)
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ViewHolder holder;

		// cek apakah convertview masih kosong
		if (convertView == null)
		{
			// jika iya maka inisialisasi item2 di single custom listview
			convertView = inflater.inflate(idLayout, null);

			holder = new ViewHolder();
			holder.ImgThumb = (ImageView) convertView.findViewById(idThumbImg);
			holder.TxtTitle = (TextView) convertView.findViewById(idTitleTxt);

			// set tag convertview
			convertView.setTag(holder);
		} else
		{
			// jika tidak kosong maka ambil tag
			holder = (ViewHolder) convertView.getTag();
		}

		holder.TxtTitle.setText(title[position]);
		holder.ImgThumb.setBackgroundResource(img[position]);

		return convertView;
	}

}
